package com.zj.syzs.ui;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.zj.shouyou.R;
import com.zj.syzs.bean.InfoBean;
import com.zj.syzs.config.UrlConfig;
import com.zj.syzs.utils.ImageDownLoader;
import com.zj.syzs.utils.JsonTask;

import java.util.HashMap;

/**
 * Created by ZJ on 2015/6/17 0017.
 */
public class GiftInfoActivity extends Activity {
    private ImageView info_icon;
    private TextView info_name, info_remain, info_total, info_stime, info_etime, info_howget, info_content, info_consume;
    private ProgressBar info_pro;
    private String id;
    private ImageDownLoader task;
    private DisplayImageOptions options;
    private InfoBean infoBean;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);
        setTitle("礼包详情");
        task = new ImageDownLoader(getApplicationContext());
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getApplicationContext()));
        DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder();
        builder.showImageOnLoading(R.mipmap.ic_launcher);
        builder.showImageOnFail(R.mipmap.ic_launcher);
        builder.cacheInMemory(true).cacheOnDisk(true);
        builder.displayer(new RoundedBitmapDisplayer(20));
        options = builder.build();

        initView();
        initData();
    }


    private void initView() {
        info_icon = (ImageView) findViewById(R.id.info_icon);
        info_name = (TextView) findViewById(R.id.info_name);
        info_remain = (TextView) findViewById(R.id.info_remain);
        info_total = (TextView) findViewById(R.id.info_total);
        info_stime = (TextView) findViewById(R.id.info_stime);
        info_etime = (TextView) findViewById(R.id.info_etime);
        info_howget = (TextView) findViewById(R.id.info_howget);
        info_content = (TextView) findViewById(R.id.info_content);
        info_consume = (TextView) findViewById(R.id.info_consume);
        info_pro = (ProgressBar) findViewById(R.id.info_pro);
    }

    private void initData() {
        HashMap<String, String> map = new HashMap<>();
        map.put("token", "a46f90a021aec5a011dbec7488a11a25");
        map.put("uid", "");
        map.put("compare", "2e8bffa93bab9f446de91762cde60c82");
        map.put("id", getIntent().getStringExtra("id"));

        new JsonTask(map, new JsonTask.CallBackObject() {
            public void loader(String json) {
                infoBean = JSON.parseObject(json, InfoBean.class);
                info_consume.setText(infoBean.getInfo().getConsume()+"Q币");
                info_content.setText(infoBean.getInfo().getContent());
                info_etime.setText(infoBean.getInfo().getEtime());
                info_stime.setText(infoBean.getInfo().getStime());
                info_howget.setText(infoBean.getInfo().getHowget());
                info_name.setText(infoBean.getInfo().getName());
                info_remain.setText(infoBean.getInfo().getRemain());
                info_total.setText(infoBean.getInfo().getTotal());
                info_pro.setMax(Integer.parseInt(infoBean.getInfo().getTotal()));
                info_pro.setProgress(Integer.parseInt(infoBean.getInfo().getRemain()));
                ImageLoader.getInstance().displayImage(infoBean.getInfo().getIcon(), info_icon, options);
            }
        }).execute(UrlConfig.SEARCH_INFO_URL);
    }
}
